;(function($) {
	if(typeof Base == "undefined") {
        Base = {};   
        window.Base = Base; 
    }
	$.extend(Base,  {
//		"ctxPath": "/cdsim/",
//		"serverPath": "http://192.168.24.131:8088/cdsi_mobile/",
		"serverPath": "http://118.112.188.108:8013/",
		"staticsPath": "statics/" 	
	});
	//接口地址
	Base.urlPath = {
		"test": "demo/helloworld",
        "forward": "forward/cdsim"
	}
	
	/**
	 * 点击事件 
	 * @method click
	 * @param {string} selector 必选 选择器
	 * @param {string} act 可选 点击效果class
	 * @param {function} func 必须 选择器
	 */
	Base.click = function(selector, func, act) {
		$(document).on("click", selector, func);
	}
	/**
     * 显示gifMask
     * @method showGifMask
     */
    Base.showGifMask = function() {
    	if($("body").find(".gm-mask").length > 0 ) {
    		return false;
    	}
    	var width = $("html").width();
    	var height = $("html").height();
    	var $mask = $("<div class=\"gm-mask\"></div>");
    	var $gif = $("<div class='gm-wrap'><div class='gm-ub'><div class=\"gm-gif\"><i></i><b></b></div></div></div>");
    	$mask.css("width", width);
    	$mask.css("height", height);
    	$gif.css("width", width);
    	$gif.css("height", height);
    	$("body").append($mask).append($gif);
    }
    /**
     * 移除gifMask（与showGifMask相对应）
     * @method removeGifMask
     */
    Base.removeGifMask = function() {
    	$(".gm-mask").remove();
    	$(".gm-wrap").remove();
    }
    /**
     * 消息提示（轻）
     * @method msgTip
     * @param {String} msg 必选 提示内容
     * @param {time: 持续时间, top: top, left: left, bottom: bottom, right: right} 可选
     */
    Base.msgTip = function(msg, param) {
    	if(arguments.length == 1) {
    		param = {};
    	}
    	var _t = param["time"] || 2000;
    	var style = "style='";
    	var _top = param["top"];
    	if(_top) {
    		style += "top:"+_top+";";
    	}
    	var _bottom = param["bottom"];
    	if(_bottom) {
    		style += "bottom:"+_bottom+";";
    	}
    	var _left = param["left"];
    	if(_left) {
    		style += "left:"+_left+";";
    	}
    	var _right = param["right"];
    	if(_right) {
    		style += "right:"+_right+";";
    	}
    	style += "'";
    	var $div = $("<div class=\"md-msgtip\" "+style+"><div class='mm-msg'>" + msg + "</div></div>");
    	$("body").append($div);
    	setTimeout(function() {
    		$div.remove();
    	}, _t);
    }
    /**
     * 创建上拉下拉刷新
     * @param {int} type 0/不传： 上拉下拉刷新； 1：下拉刷新；2：上拉刷新
     */
    Base.creatRefresh = function(type, down, up) {
    	if(down == undefined) {
    		down = function() {
    			setTimeout(function() {
    				Base.removeDown();
    			}, 1000);
    		};
    	}
    	if(up == undefined) {
    		up = function() {
				setTimeout(function() {
					Base.removeUp();
    			}, 1000);
    		};
    	}
    	var top = $(".md-header").height() || 0;
    	var paddingBottom = $("footer").height() || 0;
    	var d1 = ('<div id="pullrefresh" class="mdui-content mdui-scroll-wrapper" style="top: '+top+'px; padding-bottom: '+paddingBottom+'px;">' +
    		     '<div class="mdui-scroll"></div></div>');
    	$(".md-content").wrap(d1);
    	if(typeof mdui == "undefined") {
    		Base.msgTip("未定义mdui");
    		return false;
    	}
    	var pr = {
    		pullRefresh: {
    			container: '#pullrefresh',
    		}	
    	}
    	if(type == 1) {
    		pr.pullRefresh.down = {
    			callback: down	
    		}
    	} else if(type == 2) {
    		pr.pullRefresh.up = {
    			contentrefresh: '正在加载...',	
    			callback: up	
    		}
    	} else {
    		pr.pullRefresh.down = {
    			callback: down	
    		}
    		pr.pullRefresh.up = {
    			contentrefresh: '正在加载...',	
    			callback: up	
    		}
    	}
    	mdui.init(pr);
    }
    Base.removeDown = function() {
    	mdui('#pullrefresh').pullRefresh().endPulldownToRefresh();
    }
    Base.removeUp = function() {
    	mdui('#pullrefresh').pullRefresh().endPullupToRefresh();
    }
    //获得参数
    Base.getParams = function() {
    	var data = {};
    	if(Base.isPC() === true) {
    		var href = decodeURI(decodeURI(window.location.search.substring(1)));
    		var arr = href.split("&");
    		for(var i = 0; i < arr.length; i++) {
    			var d = arr[i].split("=");
    			data[d[0]] = d[1];
    		}
    	} else {
    		var data = md.pageParam;
    	}
    	return data;
    }
    //刷新页面
    Base.refreshWin = function() {
    	window.location.reload();
    }
    /**
     * 没有网络显示显示
     */
    Base.noNetworkPage = function(selector) {
    	var $n = $(selector);
    	if(!$n[0]) {
    		$n = $(".md-content");
    	}
    	var div = '' +
    	'<div class="md-box md-ac md-pc md-ver md-f1">'+
	    	'<div class="md-box no-img md-img"></div>'+
	    	'<div class="md-box no-text1">网络错误找不到页面~~</div>'+
	    	'<div class="md-box no-text2">点击屏幕重新尝试</div>'+
	    '</div';
    };
    /**
     * 没有数据显示显示
     */
    Base.noDataPage = function(selector, text) {
    	var $n = $(selector);
    	if(!$n[0]) {
    		$n = $(".md-content");
    	}
    	if(text == undefined){
    		text = "无相关数据";
    	}
    	var div = '' +
    	'<div class="md-box md-ac md-pc md-ver md-f1">'+
    	'<div class="md-box no-page-img md-img"></div>'+
    	'<div class="md-box no-text1">'+text+'</div>'+
    	'</div';
    	$n.html(div);
    	/*$n.tap(function() {
    		Base.refreshWin();
    	});*/
    };
    /**
     * 请求服务
     * @method requestServer 
     * @param {String} urlType 根据类型取得服务器地址 必选
     * @param {String} data 请求参数对象  必选可为null， 
     * @param {String} callback 回调方法  可选
     * @param {Boolean} mask 是否显示蒙层 可选 默认false
     * @param {String} type 请求方式:post,get 可选  默认post
     */
    Base.requestServer = function (urlType, param, callback, mask, type, nopage) {
    	urlType = Base.trim(urlType);
    	var url = ""; 
    	if(urlType.indexOf("http://") != -1) {
    		url = urlType;
    	} else {
    		url = Base.serverPath + Base.urlPath[urlType];
    	}
    	param = param || {};
    	type = type || "post";
    	var access_token = Base.getStorage("access_token");
        if(access_token == undefined) {
            access_token = "";
        }
        if(Base.isObject(param)) {
            param["access_token"] = access_token;
        }
        if(Base.isArray(param)) {
            param.push({"name": "access_token", "value": access_token});
        }
    	if(mask) {
    		Base.showGifMask();
    	} 
//        alert(url + "---" + Base.jsonToStr(param));
    	var ajax = $.ajax({
            type: type,
			contentType : "application/x-www-form-urlencoded; charset=utf-8", // post提交乱码
            url: url,
            data: param,
            success: function(data) {
            	Base.removeGifMask();
//                alert("***" + data);
                if(typeof data == "string") {
                    data = eval("(" + data + ")");
                }
                callback(data);
            },
            error: function(xhr, type) {
          		Base.removeGifMask();
          		Base.msgTip("网络错误");
            }
    	});
    	return ajax;
    }
}($));